//
//  M1HomeDetailsCertificationVC.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/26.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1HomeDetailsCertificationVC.h"
#import "M1HomeModel.h"
#import "M1CertificationVC.h"

@interface M1HomeDetailsCertificationVC ()

@property (nonatomic, strong) UIImageView *m1_icon;

@property (nonatomic, strong) UIView *m1_certificationView;

@end

@implementation M1HomeDetailsCertificationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.navigationItem.title = self.m1_title;
    
    UIImageView *bgImage = [[UIImageView alloc] initWithFrame:self.view.bounds];
    [bgImage setImage:LOAD_LOCAL_IMG(@"personal_image_cerBgView")];
    bgImage.contentMode = UIViewContentModeScaleAspectFill;
    bgImage.clipsToBounds = YES;
    [self.view addSubview:bgImage];
    
    [self m1_createUI];
    
}

- (void)m1_commitAction:(UIButton *)sender{
    if (![M1User user]) {
        WEAKSELF
        [M1Alert m1_alertWithTitle:nil message:m1_loginText buttonTitles:@[@"取消", @"登录"] action:^(NSInteger index) {
            if (index == 1) {
                M1LoginVC *loginVC = [[M1LoginVC alloc] init];
                loginVC.m1_changeNavTitleColor = YES;
                loginVC.m1_changeBackImage = YES;
                [weakSelf.navigationController pushViewController:loginVC animated:YES];
            }
        }];
        return;
    }

    NSString *page = @[@"M1CertifyCarVC", @"M1CertifyHouseVC", @"M1CertifyEducationVC"][self.m1_type];
    NSString *title = @[@"汽车信息", @"房产信息", @"学历信息"][self.m1_type];
    UIViewController *vc = [[NSClassFromString(page) alloc] init];
    vc.title = title;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)m1_createUI{
    
    self.m1_icon = [[UIImageView alloc] init];
    [self.view addSubview:_m1_icon];
    
    CGFloat height = m1_NAV_HEIGHT + (iPhone5?15:80);
    [_m1_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view.mas_centerX);
        make.top.offset(height);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    NSString *imageStr = @[@"personal_cer_cars", @"personal_cer_house", @"personal_cer_education", @"personal_cer_idcard"][self.m1_type];
    
    _m1_icon.image = LOAD_LOCAL_IMG(imageStr);
    
    [self m1_cerView];
    
}

- (void)m1_cerView{
    self.m1_certificationView = [[UIView alloc] init];
    [self.view addSubview:_m1_certificationView];
    
    [_m1_certificationView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m1_icon.mas_bottom).offset(49);
        make.centerX.equalTo(self.view.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(SCREENWIDTH, 325));
    }];
    
    UILabel *title = [[UILabel alloc] init];
    title.text = @[@"汽车信息", @"房产信息", @"学历信息", @"实名信息"][self.m1_type];
    title.textColor = m1_color(0xFFFFFF);
    title.font = m1_font(25);
    [_m1_certificationView addSubview:title];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.centerX.equalTo(self.m1_certificationView.mas_centerX);
    }];
    
    NSString *house;
    if ([self.m1_model.basic.house_info.number integerValue] == 0) {
        house = self.m1_model.basic.house_info.title;
    }else{
        house = [NSString stringWithFormat:@"已购%@套房\n%@", self.m1_model.basic.house_info.number, self.m1_model.basic.house_info.house_abode];
    }
    
    NSString *car;
    
    if ([self.m1_model.basic.car_info.number integerValue] == 0) {
        car = self.m1_model.basic.car_info.title;
    }else{
        car = [NSString stringWithFormat:@"已购%@辆车\n%@", self.m1_model.basic.car_info.number, self.m1_model.basic.car_info.car_brand];
    }
    
    NSString *text = @[car,
                       house,
                       [NSString stringWithFormat:@"%@\n%@", self.m1_model.basic.education_info.school, self.m1_model.basic.education_info.desc],
                       [NSString stringWithFormat:@"%@\n%@", self.m1_model.basic.identity_info.name, self.m1_model.basic.identity_info.card]][self.m1_type];

    UILabel *content = [[UILabel alloc] init];
    content.text = text;
    content.textColor = m1_color(0xFFFFFF);
    content.font = m1_font(25);
    content.textAlignment = NSTextAlignmentCenter;
    content.numberOfLines = 3;
    [_m1_certificationView addSubview:content];
    
    [content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(title.mas_bottom).offset(45);
        make.left.offset(50);
        make.right.offset(-50);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @[@"成功完善汽车信息", @"成功完善房产信息", @"成功完善学历信息", @"成功完善实名信息"][self.m1_type];
    label.textColor = m1_color(0x999999);
    label.font = m1_font(16);
    [_m1_certificationView addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_certificationView.mas_centerX);
        make.top.equalTo(content.mas_bottom).offset(35);
    }];
    
    UILabel *label1 = [[UILabel alloc] init];
    
    label1.text = [self m1_timeStamp:@[self.m1_model.basic.car_info.car_auth.auth_time, self.m1_model.basic.house_info.house_auth.auth_time, self.m1_model.basic.education_info.education_auth.auth_time, self.m1_model.basic.identity_info.identity_auth.auth_time][self.m1_type]];
    label1.textColor = m1_color(0x999999);
    label1.font = m1_font(16);
    [_m1_certificationView addSubview:label1];
    
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.m1_certificationView.mas_centerX);
        make.top.equalTo(label.mas_bottom).offset(11);
    }];
    
    if ((self.m1_type == 0 && [M1User user].basic.car_info.car_auth.auth_status != 1) ||
        (self.m1_type == 1 && [M1User user].basic.house_info.house_auth.auth_status != 1) ||
        (self.m1_type == 2 && [M1User user].basic.education_info.education_auth.auth_status != 1)) {
        UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        commitBtn.backgroundColor = m1_color(0xDBB76B);
        [commitBtn setTitle:@"我也要认证" forState:UIControlStateNormal];
        [commitBtn setTitleColor:m1_color(0xFFFFFF) forState:UIControlStateNormal];
        [commitBtn addTarget:self action:@selector(m1_commitAction:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:commitBtn];
        
        commitBtn.layer.cornerRadius = 45 / 2;
        commitBtn.layer.masksToBounds = YES;
        
        [commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.m1_certificationView.mas_centerX);
            make.bottom.offset(iPhone5?-10:-30);
            make.size.mas_equalTo(CGSizeMake(200, 45));
        }];
    }
    
    
    
    
//    200 45
}

- (NSString *) m1_timeStamp:(NSString *)stamp{
    NSDateFormatter *m1_dateFormatter = [[NSDateFormatter alloc] init];
    [m1_dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Shanghai"]];
    NSDate *assignedDateVal=[NSDate dateWithTimeIntervalSince1970:[stamp integerValue]];
    [m1_dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *m1_dateStr = [m1_dateFormatter stringFromDate:assignedDateVal];
    NSDate * needFormatDate = [m1_dateFormatter dateFromString:m1_dateStr];
    NSString *time = [m1_dateFormatter stringFromDate:needFormatDate];
    
    return [NSString stringWithFormat:@"审核通过时间%@", time];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
